home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 62
/
Volume 62 - JOGO DISK .iso
/
Games
/
penguin_dinner.swf
/
scripts
/
__Packages
/
classes
/
game
/
GameBoard.as
< prev
next >
Wrap
Text File
|
2008-03-17
|
16KB
|
385 lines
class classes.game.GameBoard extends classes.ui.AbstractWidget
{
var pickupMoneyMessageTimeoutID = null;
function GameBoard()
{
super();
this.widgetMan = classes.core.WidgetManager.getInstance();
this.soundMan = classes.core.SoundManager.getInstance();
this.soundMan.startMusicTrack("game_track");
this.doLater(this.init);
}
function init()
{
classes.core.SOManager.getInstance().__set__dayScore(0);
this.tv_clip.gotoAndStop("tv_" + String(classes.core.SOManager.getInstance().__get__upgradeTV()));
var _loc10_ = classes.core.SOManager.getInstance().__get__currentStage();
this.background_mc.gotoAndStop("stage_" + _loc10_);
this.pause_btn.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
this.company_btn.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
this.trashcan_btn.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
var _loc5_ = [new classes.math.Tile(11,1),new classes.math.Tile(23,1),new classes.math.Tile(17,5),new classes.math.Tile(11,10),new classes.math.Tile(23,10)];
var _loc8_ = [new classes.math.Tile(11,1),new classes.math.Tile(23,1),new classes.math.Tile(17,2),new classes.math.Tile(11,7),new classes.math.Tile(23,7)];
var _loc7_ = [new classes.math.Tile(8,1),new classes.math.Tile(20,1),new classes.math.Tile(14,5),new classes.math.Tile(8,10),new classes.math.Tile(20,10)];
var _loc6_ = [new classes.math.Tile(14,1),new classes.math.Tile(26,1),new classes.math.Tile(20,5),new classes.math.Tile(14,10),new classes.math.Tile(26,10)];
var _loc9_ = [[8,8],[8,8],[8,8],[10,8],[8,10]];
this.allOrderPlates = [];
this.allTables = [];
var _loc2_ = 0;
while(_loc2_ < 5)
{
var _loc4_ = this["order_plate_btn_" + _loc2_];
_loc4_.index = _loc2_;
_loc4_.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
this.allOrderPlates.push(_loc4_);
var _loc3_ = this.objects_mc["table_" + _loc2_];
this["table_" + _loc2_] = _loc3_;
this.allTables.push(_loc3_);
_loc3_.tileUpCoords = _loc8_[_loc2_];
_loc3_.tileDownCoords = _loc5_[_loc2_];
_loc3_.tileLeftPlace = _loc7_[_loc2_];
_loc3_.tileRightPlace = _loc6_[_loc2_];
_loc3_.guestsSpeeds = _loc9_[_loc2_];
_loc3_.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
_loc2_ = _loc2_ + 1;
}
this.goal_tf.text = String(classes.game.GameData.__get__DAY_GOAL());
this.score_tf.text = String(0);
this.lastCommand = null;
this.hero = this.objects_mc.hero;
this.heroQueue = new classes.game.HeroCommandQueue();
this.guestsQueue = [];
classes.game.Guest.selectedGuests = [];
this.nextGuestAppearCounter = Math.floor(classes.game.GameData.__get__GUEST_APPEAR_TIME() * 0.5);
this.attachedClipCount = 0;
this.foodCooking = [];
this.showClosedSign = true;
this.totalGuestsOnScreen = 0;
this.timer = new classes.utils.Timer(classes.game.GameData.DAY_TIME);
this.gamePaused = false;
this.startLocalLoop(this.update);
}
function onButtonClick(e)
{
switch(e.target)
{
case this.table_0:
case this.table_1:
case this.table_2:
case this.table_3:
case this.table_4:
var _loc3_ = this.hero._y < e.target._y ? e.target.tileUpCoords : e.target.tileDownCoords;
this.heroQueue.enqueue(new classes.game.Command(classes.game.Command.TYPE_MOVE_TO_TABLE,e.target,{tileX:_loc3_.x,tileY:_loc3_.y}));
break;
case this.order_plate_btn_0:
case this.order_plate_btn_1:
case this.order_plate_btn_2:
case this.order_plate_btn_3:
case this.order_plate_btn_4:
this.heroQueue.enqueue(new classes.game.Command(classes.game.Command.TYPE_MOVE_TO_ORDER_PLATE,e.target,{tileX:15 - 3 * e.target.index,tileY:11}));
break;
case this.trashcan_btn:
this.heroQueue.enqueue(new classes.game.Command(classes.game.Command.TYPE_MOVE_TO_TRASHCAN,this.trashcan_btn));
break;
case this.pause_btn:
this.widgetMan.lockAllGlobal();
this.lastCommand = new classes.game.Command(classes.game.Command.TYPE_PAUSE_GAME);
break;
case this.company_btn:
classes.utils.URLCaller.mainLink();
}
}
function unpauseGame()
{
for(var _loc3_ in this.objects_mc)
{
var _loc2_ = this.objects_mc[_loc3_];
if(_loc2_.__proto__ == classes.game.Guest.prototype)
{
_loc2_.unpause();
}
}
classes.core.WidgetManager.getInstance().unlockAllGlobal();
this.timer.unpause();
this.gamePaused = false;
}
function update()
{
if(this.gamePaused)
{
return undefined;
}
if(this.lastCommand.type == classes.game.Command.TYPE_PAUSE_GAME)
{
this.gamePaused = true;
this.lastCommand = null;
this.heroQueue.clear();
for(var _loc10_ in this.objects_mc)
{
var _loc7_ = this.objects_mc[_loc10_];
if(_loc7_.__proto__ == classes.game.Guest.prototype)
{
_loc7_.pause();
}
}
this.pauseMenu = classes.core.WidgetManager.getInstance().createWidget(classes.core.WidgetManager.WIDGET_PAUSE_MENU,this,this.getNextHighestDepth());
this.pauseMenu.addEventListener(classes.ui.AbstractWidget.DISPOSE,this,"unpauseGame");
return undefined;
}
this.timer.update();
var _loc17_ = Math.floor((1 - this.timer.__get__percentLeft()) * 1000);
this.background_mc.clock.gotoAndStop(_loc17_);
this.background_mc.atmospheric.gotoAndStop(_loc17_);
if(this.timer.__get__percentLeft() == 0)
{
if(this.showClosedSign)
{
this.showClosedSign = false;
this.objects_mc.attachMovie("closed_sign","closed_sign",this.objects_mc.getNextHighestDepth(),{_x:50,_y:210});
}
if(this.totalGuestsOnScreen == 0)
{
var _loc16_ = 0;
for(_loc10_ in this.allTables)
{
var _loc14_ = this.allTables[_loc10_];
_loc16_ += _loc14_.earnings;
}
if(_loc16_ == 0)
{
this.stopLocalLoop();
classes.core.Application.getInstance().gotoDayResultScreen();
return undefined;
}
if(this.pickupMoneyMessageTimeoutID == null)
{
this.pickupMoneyMessageTimeoutID = _global.setTimeout(this,"showPickupMoneyMessage",4000);
}
}
}
this.lastCommand = this.heroQueue.dequeue();
if(this.lastCommand != null)
{
switch(this.lastCommand.type)
{
case classes.game.Command.TYPE_MOVE_TO_TRASHCAN:
this.hero.targetObj = this.lastCommand.target;
this.hero.moveTo(21,11);
break;
case classes.game.Command.TYPE_MOVE_TO_ORDER_PLATE:
this.hero.targetObj = this.lastCommand.target;
this.hero.moveTo(this.lastCommand.data.tileX,this.lastCommand.data.tileY);
break;
case classes.game.Command.TYPE_MOVE_TO_TABLE:
_loc14_ = this.lastCommand.target;
var _loc11_ = classes.game.Guest.selectedGuests;
if(_loc11_.length > 0 && _loc14_.isFree())
{
_loc10_ = 0;
while(_loc10_ < _loc11_.length)
{
_loc11_[1].speed = _loc14_.guestsSpeeds[_loc10_];
_loc11_[_loc10_].moveToTable(_loc14_);
_loc10_ = _loc10_ + 1;
}
this.onGuestLeaveQueue();
this.heroQueue.open();
}
else
{
this.hero.targetObj = this.lastCommand.target;
this.hero.moveTo(this.lastCommand.data.tileX,this.lastCommand.data.tileY);
}
}
}
this.nextGuestAppearCounter = this.nextGuestAppearCounter + 1;
if(this.nextGuestAppearCounter >= classes.game.GameData.__get__GUEST_APPEAR_TIME() && this.timer.__get__percentLeft() > 0)
{
if(this.guestsQueue.length < 3 && this.totalGuestsOnScreen < classes.game.GameData.__get__MAX_GUESTS_AT_ONCE())
{
this.addNewGuest();
}
this.nextGuestAppearCounter = 0;
}
for(_loc10_ in this.objects_mc)
{
_loc7_ = this.objects_mc[_loc10_];
_loc7_.update();
var _loc9_ = Math.floor((_loc7_._y - 140) / 20) * 100 + Math.floor((_loc7_._x + 20) / 20);
if(!_loc7_.atTable)
{
_loc9_ += 50;
}
if(_loc7_.getDepth() != _loc9_)
{
_loc7_.swapDepths(_loc9_);
}
}
if(this.hero.targetObjReached)
{
switch(this.hero.targetObj)
{
case this.table_0:
case this.table_1:
case this.table_2:
case this.table_3:
case this.table_4:
_loc14_ = this.hero.targetObj;
var _loc12_ = _loc14_.guests;
if(_loc12_.length == 0 && _loc14_.earnings > 0)
{
this.soundMan.startSound("money_pickup");
classes.core.SOManager.getInstance().dayScore = classes.core.SOManager.getInstance().dayScore + _loc14_.earnings;
this.score_tf.text = String(classes.core.SOManager.getInstance().__get__dayScore());
_loc14_.takeMoney();
}
else
{
_loc10_ = 0;
while(_loc10_ < _loc12_.length)
{
var _loc6_ = _loc12_[_loc10_];
switch(_loc6_.state)
{
case classes.game.Guest.STATE_WAITING_FOR_WAITER:
_loc6_.makeOrder();
this.foodCooking.push({type:_loc6_.food,time:0});
break;
case classes.game.Guest.STATE_WAITING_FOR_FOOD:
if(this.hero.giveFood(_loc6_.food))
{
this.soundMan.startSound("food_give");
_loc6_.startEating();
_loc14_.showFood(_loc6_);
}
}
_loc10_ = _loc10_ + 1;
}
}
break;
case this.order_plate_btn_0:
case this.order_plate_btn_1:
case this.order_plate_btn_2:
case this.order_plate_btn_3:
case this.order_plate_btn_4:
var _loc5_ = this.hero.targetObj;
if(this.hero.takeReadyFood(_loc5_.foodType))
{
this.soundMan.startSound("food_pickup");
_loc5_.setType(classes.game.Food.TYPE_NONE);
}
break;
case this.trashcan_btn:
this.hero.clearFood();
}
this.heroQueue.open();
}
var _loc4_ = 0;
while(_loc4_ < this.foodCooking.length)
{
var _loc8_ = this.foodCooking[_loc4_];
_loc8_.time = _loc8_.time + 1;
if(_loc8_.time >= classes.game.GameData.__get__FOOD_COOKING_TIME())
{
var _loc3_ = 0;
while(_loc3_ < 5)
{
_loc5_ = this["order_plate_btn_" + _loc3_];
if(_loc5_.foodType == classes.game.Food.TYPE_NONE)
{
this.soundMan.startSound("food_ready");
_loc5_.setType(_loc8_.type);
this.foodCooking.splice(_loc4_,1);
_loc4_ = _loc4_ - 1;
break;
}
_loc3_ = _loc3_ + 1;
}
}
_loc4_ = _loc4_ + 1;
}
this.lastCommand = null;
}
function showPickupMoneyMessage()
{
this.attachMovie("pickup_money_warning","pickup_money_warning",this.getNextHighestDepth());
this.soundMan.startSound("message_popup");
}
function addNewGuest()
{
var _loc3_ = this.guestsQueue.length;
if(Math.random() <= classes.game.GameData.__get__GUEST_DOUBLE_APPEAR_PROBABILITY())
{
this.objects_mc.attachMovie("guest","guest_" + this.attachedClipCount,this.attachedClipCount);
var _loc2_ = this.objects_mc["guest_" + this.attachedClipCount];
this.attachedClipCount = this.attachedClipCount + 1;
this.objects_mc.attachMovie("guest","guest_" + this.attachedClipCount,this.attachedClipCount);
var _loc5_ = this.objects_mc["guest_" + this.attachedClipCount];
this.attachedClipCount = this.attachedClipCount + 1;
_loc2_.speed = 9;
_loc5_.speed = 8;
var _loc6_ = [[new classes.math.Tile(7,2),new classes.math.Tile(6,4)],[new classes.math.Tile(5,2),new classes.math.Tile(4,4)],[new classes.math.Tile(3,2),new classes.math.Tile(2,4)]];
_loc2_.setup(_loc5_,new classes.math.Tile(0,2),_loc6_[_loc3_][0],_loc3_ == 0);
_loc5_.setup(_loc2_,new classes.math.Tile(0,4),_loc6_[_loc3_][1],_loc3_ == 0);
_loc2_.addEventListener(classes.game.Guest.EVENT_LEAVE_QUEUE,this,"onGuestLeaveQueue");
_loc2_.addEventListener(classes.game.Guest.EVENT_LEAVE_SCREEN,this,"onGuestLeaveScreen");
this.guestsQueue.push([_loc2_,_loc5_]);
}
else
{
this.objects_mc.attachMovie("guest","guest_" + this.attachedClipCount,this.attachedClipCount);
var _loc4_ = this.objects_mc["guest_" + this.attachedClipCount];
this.attachedClipCount = this.attachedClipCount + 1;
_loc4_.speed = 8;
var _loc7_ = [new classes.math.Tile(6,3),new classes.math.Tile(4,3),new classes.math.Tile(2,3)];
_loc4_.setup(null,new classes.math.Tile(0,3),_loc7_[_loc3_],_loc3_ == 0);
_loc4_.addEventListener(classes.game.Guest.EVENT_LEAVE_QUEUE,this,"onGuestLeaveQueue");
_loc4_.addEventListener(classes.game.Guest.EVENT_LEAVE_SCREEN,this,"onGuestLeaveScreen");
this.guestsQueue.push([_loc4_]);
}
this.totalGuestsOnScreen = this.totalGuestsOnScreen + 1;
}
function onGuestLeaveScreen(e)
{
this.totalGuestsOnScreen = this.totalGuestsOnScreen - 1;
}
function onGuestLeaveQueue(e)
{
this.guestsQueue.shift();
var _loc2_ = 0;
while(_loc2_ < this.guestsQueue.length)
{
var _loc3_ = 0;
while(_loc3_ < this.guestsQueue[_loc2_].length)
{
var _loc4_ = this.guestsQueue[_loc2_][_loc3_];
_loc4_.shiftInQueue(_loc2_ == 0);
_loc3_ = _loc3_ + 1;
}
_loc2_ = _loc2_ + 1;
}
classes.game.Guest.selectedGuests = [];
}
function dispose()
{
this.pause_btn.dispose();
this.company_btn.dispose();
this.trashcan_btn.dispose();
if(this.pauseMenu)
{
this.pauseMenu.dispose();
}
for(var _loc5_ in this.allOrderPlates)
{
var _loc3_ = this.allOrderPlates[_loc5_];
_loc3_.dispose();
}
for(_loc5_ in this.allTables)
{
var _loc4_ = this.allTables[_loc5_];
_loc4_.dispose();
}
super.dispose();
}
}